//
//  DepositsUserAuthCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/17.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "DepositsUserAuthCell.h"

@interface DepositsUserAuthCell()<UITextFieldDelegate>


@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) UILabel *titleLB;

@property (nonatomic,strong) UILabel *subTitleLB;

@property (nonatomic,strong) UITextField *name_TF;

@property (nonatomic,strong) UITextField *idCard_TF;

@property (nonatomic,strong) UIView *lineV;

@end

@implementation DepositsUserAuthCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = MainBackColor;
        self.backgroundColor = MainBackColor;
        
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setDeposDict:(NSMutableDictionary *)deposDict{
    _deposDict = deposDict;
    NSString *name = _deposDict[@"name"];
    NSString *cardNo = _deposDict[@"idcard"];
    self.name_TF.text = name;
    self.idCard_TF.text = cardNo;
}

#pragma mark - UI
-(void)initUI{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.titleLB];
    [self.bgView addSubview:self.subTitleLB];
    [self.bgView addSubview:self.name_TF];
    [self.bgView addSubview:self.lineV];
    [self.bgView addSubview:self.idCard_TF];
}

#pragma mark - lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 170)];
        _bgView.backgroundColor = UIColor.whiteColor;
    }
    return _bgView;
}
- (UILabel *)titleLB{
    if (!_titleLB) {
        _titleLB = [[UILabel alloc] initWithFrame:CGRectMake(14, 24, 80*Width_Scale, 22)];
        _titleLB.text = @"实名认证";
        _titleLB.font = FontSetWithWeight(16, 0.3f);
        _titleLB.textAlignment = NSTextAlignmentLeft;
        _titleLB.textColor = MainBlackTextColor;
    }
    return _titleLB;
}
- (UILabel *)subTitleLB{
    if (!_subTitleLB) {
        _subTitleLB = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLB.right + 5, self.titleLB.top+2, 80*Width_Scale, 18)];
        _subTitleLB.text = @"(全部必填)";
        _subTitleLB.font = FontSet(13);
        _subTitleLB.textAlignment = NSTextAlignmentLeft;
        _subTitleLB.textColor = MainGrayTextColor;
    }
    return _subTitleLB;
}

- (UITextField *)name_TF{
    if (!_name_TF) {
        _name_TF = [[UITextField alloc] initWithFrame:CGRectMake(14, self.titleLB.bottom+20, ScreenWidth-28, 30)];
        _name_TF.textColor = MainBlackTextColor;
        _name_TF.font = FontSet(15);
        _name_TF.placeholder = @"请输入联系人真实姓名";
        _name_TF.textAlignment = NSTextAlignmentRight;
        _name_TF.leftView = [self leftViewWithTitle:@"姓名"];
        _name_TF.leftViewMode = UITextFieldViewModeAlways;
        _name_TF.delegate = self;
    }
    return _name_TF;
}
- (UIView *)lineV{
    if (!_lineV) {
        _lineV = [[UIView alloc] initWithFrame:CGRectMake(10, self.name_TF.bottom+15, ScreenWidth-20, 1)];
        _lineV.backgroundColor = MainPureColor(239);
    }
    return _lineV;
}
- (UITextField *)idCard_TF{
    if (!_idCard_TF) {
        _idCard_TF = [[UITextField alloc] initWithFrame:CGRectMake(14, self.lineV.bottom+15, ScreenWidth-28, 30)];
        _idCard_TF.textColor = MainBlackTextColor;
        _idCard_TF.font = FontSet(15);
        _idCard_TF.placeholder = @"请输入联系人身份证";
        _idCard_TF.textAlignment = NSTextAlignmentRight;
        _idCard_TF.leftView = [self leftViewWithTitle:@"身份证"];
        _idCard_TF.keyboardType = UIKeyboardTypeNumberPad;
        _idCard_TF.leftViewMode = UITextFieldViewModeAlways;
        _idCard_TF.delegate = self;
    }
    return _idCard_TF;
}
//uitextfield  左侧view
-(UIView *)leftViewWithTitle:(NSString *)title{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 30)];
    UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 80, 20)];
    lb.text = title;
    lb.textAlignment = NSTextAlignmentLeft;
    lb.textColor = UIColor.blackColor;
    lb.font = FontSet(15);
    [view addSubview:lb];
    return view;
}

#pragma mark - UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField == self.name_TF) {
        self.deposDict[@"name"] = textField.text;
    }else{
        self.deposDict[@"idcard"] = textField.text;
    }
    if (self.updateDeposBlock) {
        self.updateDeposBlock(self.deposDict);
    }
}



@end
